Skip to content

fix(ack-pay): preserve original error cause in verifyPaymentRequestToken#65

Open
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:fix/payment-request-error-cause
Open

fix(ack-pay): preserve original error cause in verifyPaymentRequestToken#65
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:fix/payment-request-error-cause

Conversation

@ak68a
Copy link
Copy Markdown

@ak68a ak68a commented Mar 25, 2026

Summary

  • Preserve the original JWT verification error as an Error Cause when throwing InvalidPaymentRequestTokenError
  • Update the error constructor to accept ErrorOptions

Previously, the catch block discarded the original error (expired token, bad signature, DID resolution failure), making it difficult to diagnose payment request verification failures. The original error is now available via .cause.

Test plan

  • All 32 existing ack-pay tests pass unchanged
  • Error cause is accessible on caught InvalidPaymentRequestTokenError instances

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Payment token verification now preserves underlying error details when failures occur, improving diagnostics and troubleshooting.
  • Tests

    • Updated tests to assert error types and that error chaining (cause) is preserved, ensuring more robust failure validation.

AI Disclosure: This PR was developed with assistance from Claude Code (Claude Opus).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f9328f6c-efea-4d74-bc25-4cb2e27dc973

📥 Commits

Reviewing files that changed from the base of the PR and between f423169 and e74f097.

📒 Files selected for processing (1)
  • packages/ack-pay/src/verify-payment-request-token.test.ts

Walkthrough

Updated error construction and propagation for payment request token verification: the InvalidPaymentRequestTokenError constructor now accepts ErrorOptions, and the verifier preserves and attaches caught errors as cause when rethrowing; tests updated to assert instances and causes.

Changes

Cohort / File(s) Summary
Error Definition
packages/ack-pay/src/errors.ts
InvalidPaymentRequestTokenError constructor signature changed to constructor(message = "...", options?: ErrorOptions) and forwards options to super(message, options).
Error Handling
packages/ack-pay/src/verify-payment-request-token.ts
Catch block now captures the original exception (err) and rethrows InvalidPaymentRequestTokenError with { cause: err }.
Tests
packages/ack-pay/src/verify-payment-request-token.test.ts
Negative tests updated to import InvalidPaymentRequestTokenError, capture thrown errors, and assert instance, message, and cause (presence or absence) instead of using rejects.toThrow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preserving the original error cause in verifyPaymentRequestToken, which aligns with the core objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…tToken

- Verify .cause is set when JWT verification fails (invalid format, expired, bad signature)
- Verify .cause is undefined when schema validation fails (no caught error to wrap)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant